package interfacesBeans;

/**
 *
 * @author Rodrigo
 */

import agenda.*;
import javax.swing.JOptionPane;

public class VisualizarContato extends javax.swing.JPanel {

    private int posicaoContato;

    /** Creates new form VisualizarContatos */
    public VisualizarContato() {
        initComponents();
    }

    public void setInitialFieldValues(int posicaoContato) {

        this.posicaoContato = posicaoContato;
        Contato c = Body.user.getAgenda().getContatos().get(posicaoContato);

        labelNome.setText(c.getNome());
        labelEndereco.setText(c.getEndereco());
        labelDataAniversario.setText(c.getDataAniversarioFormatada());
        labelTipoFormaDeContato.setText(c.getFormasDeContato().get(0).getTipo());
        labelEnderecoContato.setText(c.getFormasDeContato().get(0).getEndereco());
        labelComentario.setText(c.getFormasDeContato().get(0).getComentario());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelVisualizarContato = new javax.swing.JLabel();
        labelNomeHeader = new javax.swing.JLabel();
        labelNome = new javax.swing.JLabel();
        labelEnderecoHeader = new javax.swing.JLabel();
        labelEndereco = new javax.swing.JLabel();
        labelDataAniversarioHeader = new javax.swing.JLabel();
        labelDataAniversario = new javax.swing.JLabel();
        labelFormaDeContatoHeader = new javax.swing.JLabel();
        labelEnderecoContato = new javax.swing.JLabel();
        labelTipoFormaDeContato = new javax.swing.JLabel();
        labelButtons = new javax.swing.JPanel();
        buttonEditar = new javax.swing.JButton();
        labelRemover = new javax.swing.JButton();
        labelVoltar = new javax.swing.JButton();
        labelComentarioHeader = new javax.swing.JLabel();
        labelComentario = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        labelVisualizarContato.setFont(new java.awt.Font("Tahoma", 1, 28));
        labelVisualizarContato.setText("Visualizar Contato");

        labelNomeHeader.setFont(new java.awt.Font("Tahoma", 1, 14));
        labelNomeHeader.setText("Nome");

        labelNome.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelNome.setText("Bzz bzz, BzzZZZZZZ!");

        labelEnderecoHeader.setFont(new java.awt.Font("Tahoma", 1, 14));
        labelEnderecoHeader.setText("Endereço");

        labelEndereco.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelEndereco.setText("Rua das colmeias, nº 42");

        labelDataAniversarioHeader.setFont(new java.awt.Font("Tahoma", 1, 14));
        labelDataAniversarioHeader.setText("Data de Aniversário");

        labelDataAniversario.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelDataAniversario.setText("21/12");

        labelFormaDeContatoHeader.setFont(new java.awt.Font("Tahoma", 1, 14));
        labelFormaDeContatoHeader.setText("Forma de Contato");

        labelEnderecoContato.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelEnderecoContato.setText("Endereço");

        labelTipoFormaDeContato.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelTipoFormaDeContato.setText("Tipo de fdc");

        labelButtons.setBackground(new java.awt.Color(255, 255, 255));

        buttonEditar.setBackground(new java.awt.Color(255, 255, 255));
        buttonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edituser.png"))); // NOI18N
        buttonEditar.setText("Editar");
        buttonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarActionPerformed(evt);
            }
        });

        labelRemover.setBackground(new java.awt.Color(255, 255, 255));
        labelRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.png"))); // NOI18N
        labelRemover.setText("Remover");
        labelRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                labelRemoverActionPerformed(evt);
            }
        });

        labelVoltar.setBackground(new java.awt.Color(255, 255, 255));
        labelVoltar.setText("Voltar");
        labelVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                labelVoltarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout labelButtonsLayout = new javax.swing.GroupLayout(labelButtons);
        labelButtons.setLayout(labelButtonsLayout);
        labelButtonsLayout.setHorizontalGroup(
            labelButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, labelButtonsLayout.createSequentialGroup()
                .addContainerGap(53, Short.MAX_VALUE)
                .addComponent(buttonEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(labelRemover)
                .addGap(33, 33, 33)
                .addComponent(labelVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50))
        );

        labelButtonsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonEditar, labelRemover, labelVoltar});

        labelButtonsLayout.setVerticalGroup(
            labelButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(labelButtonsLayout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(labelButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelRemover, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        labelButtonsLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonEditar, labelRemover, labelVoltar});

        labelComentarioHeader.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelComentarioHeader.setText("Comentário");

        labelComentario.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelComentario.setText("comment comment commentq");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(19, 19, 19)
                                .addComponent(labelVisualizarContato))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(45, 45, 45)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelEnderecoHeader)
                                    .addComponent(labelNomeHeader)
                                    .addComponent(labelNome, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                                    .addComponent(labelEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE))))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelFormaDeContatoHeader)
                            .addComponent(labelDataAniversarioHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                            .addComponent(labelDataAniversario, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(labelComentarioHeader)
                                    .addComponent(labelTipoFormaDeContato))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(labelComentario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelEnderecoContato, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(labelButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelVisualizarContato)
                        .addGap(52, 52, 52)
                        .addComponent(labelNomeHeader)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelNome))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelDataAniversarioHeader)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelDataAniversario)))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(labelEnderecoHeader)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelEndereco))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(labelFormaDeContatoHeader)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTipoFormaDeContato)
                            .addComponent(labelEnderecoContato))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelComentarioHeader)
                    .addComponent(labelComentario))
                .addGap(57, 57, 57)
                .addComponent(labelButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(90, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void labelRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_labelRemoverActionPerformed
        int option = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja remover este contato?", "Remoção de contato", JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            javax.swing.table.DefaultTableModel model = (javax.swing.table.DefaultTableModel)Body.contatos.tableContatos.getModel();
            model.removeRow(posicaoContato);

            Body.user.getAgenda().getContatos().remove(posicaoContato);

            JOptionPane.showMessageDialog(this, "Contato removido com sucesso!", "Remoção de contato", JOptionPane.INFORMATION_MESSAGE);

            java.awt.CardLayout layout = (java.awt.CardLayout) Body.panelBody.getLayout();
            layout.show(Body.panelBody, "Contatos");
        }
    }//GEN-LAST:event_labelRemoverActionPerformed

    private void labelVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_labelVoltarActionPerformed
        java.awt.CardLayout layout = (java.awt.CardLayout)Body.panelBody.getLayout();
        layout.show(Body.panelBody, "Contatos");
    }//GEN-LAST:event_labelVoltarActionPerformed

    private void buttonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarActionPerformed
        Body.editarContato.setInitialFieldValues(posicaoContato);
        java.awt.CardLayout layout = (java.awt.CardLayout)Body.panelBody.getLayout();
        layout.show(Body.panelBody, "EditarContato");
    }//GEN-LAST:event_buttonEditarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonEditar;
    private javax.swing.JPanel labelButtons;
    private javax.swing.JLabel labelComentario;
    private javax.swing.JLabel labelComentarioHeader;
    private javax.swing.JLabel labelDataAniversario;
    private javax.swing.JLabel labelDataAniversarioHeader;
    private javax.swing.JLabel labelEndereco;
    private javax.swing.JLabel labelEnderecoContato;
    private javax.swing.JLabel labelEnderecoHeader;
    private javax.swing.JLabel labelFormaDeContatoHeader;
    private javax.swing.JLabel labelNome;
    private javax.swing.JLabel labelNomeHeader;
    private javax.swing.JButton labelRemover;
    private javax.swing.JLabel labelTipoFormaDeContato;
    private javax.swing.JLabel labelVisualizarContato;
    private javax.swing.JButton labelVoltar;
    // End of variables declaration//GEN-END:variables
}
